#include "DataStorage.h"
#include "EEPROM.h"
#include <Arduino.h>
#include "log.h"

DataStorage::DataStorage(DataStorageBase* data_base):
    _db(data_base),_update(false),_last_millis(0)
{
    
}
DataStorage::~DataStorage()
{

}
void DataStorage::begin()
{
    EEPROM.begin();
    //_db->make_default();
    if(!this->load()){
        _db->make_default();
    }
}

void DataStorage::schedule()
{
    if(_update==false){
        return;
    }

    if( (millis()-_last_millis)>30000){
        _db->check_update();
        _update = false;
        _last_millis = millis();
    }
}
void DataStorage::update() 
{
    _update = true;
}

void DataStorage::cleanup()
{
    _last_millis = millis();
} 